const http = require('http');
const url = require('url');
// const { route } = require('./router');

function start(route, handle) {
    function onRequest(req, res) {
        // var postData = "";
        var pathname = url.parse(req.url).pathname;
        console.log("Request for " + pathname + " received.");
        // req.setEncoding("utf8");

        // req.addListener("data", function(postDataChunk) {
        //     postData += postDataChunk;
        //     console.log("Received POST data chunk '" + postDataChunk +"'.");
        // })

        // req.addListener("end", function() {
        //     route(handle, pathname, res, postData);
        // })
        route(handle, pathname, res, req);
    }
    http.createServer(onRequest).listen(8888);
    console.log("Server has started.")
}

// const car = {
//     brand:'Ford',
//     model:'Fiesta'
// }

//使用module.exports导出start函数
// module.exports = start;

//使用exports导出start函数
exports.start = start;